package com.danke.demo.player;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.tencent.liteav.demo.play.SuperPlayerModel;
import com.tencent.liteav.demo.play.danke.DKVideoPlayer;
import com.tencent.liteav.demo.play.danke.DKVideoPlayerManager;
import com.tencent.rtmp.TXLiveBase;

import androidx.appcompat.app.AppCompatActivity;

public class TestPlayActivity extends AppCompatActivity {

    private static final String TAG = TestPlayActivity.class.getSimpleName();
    private LinearLayout mllPlayer;
    private DKVideoPlayer mSuperPlayerView;
    private DKVideoPlayer mSuperPlayerView2;
    private TextView mBtnHaHa;
    private TextView mBtnHeHe;
    private RelativeLayout mRlRoot;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 去掉标题栏
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        // 全屏
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_test_play);

        String sdkver = TXLiveBase.getSDKVersionStr();
        Log.d(TAG, "liteav sdk version is : " + sdkver);

        mRlRoot = findViewById(R.id.root);
        mllPlayer = findViewById(R.id.ll_player);

        mBtnHaHa = findViewById(R.id.btn_haha);
        mBtnHaHa.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(TestPlayActivity.this, "哈哈", Toast.LENGTH_SHORT).show();
            }
        });
        mBtnHeHe = findViewById(R.id.btn_hehe);
        mBtnHeHe.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(TestPlayActivity.this, "呵呵", Toast.LENGTH_SHORT).show();
            }
        });

        play1();
    }

    private void play1() {
        mSuperPlayerView = findViewById(R.id.player);
        mSuperPlayerView.hideSmallTopLayout();
        // 通过URL方式的视频信息配置
        SuperPlayerModel model = new SuperPlayerModel();
//        model.title = "测试视频-720P";
        model.title = " "; // 如果不想要标题就传个空格
//        model.videoURL = "https://zhuanti.danke.com.cn/danke-vedio/danke-vedio2.mp4";
        model.videoURL = "https://1258560379.vod2.myqcloud.com/f73d85b8vodtranscq1258560379/aaeaa2ba5285890787921992208/v.f20.mp4";
        // 开始播放
        mSuperPlayerView.playWithMode(model);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        DKVideoPlayerManager.getInstance().onDestroy();
    }

    @Override
    public void onBackPressed() {
        if (DKVideoPlayerManager.getInstance().onBackPressed()) {
            return;
        }
        super.onBackPressed();
    }
}
